var editor
;
(function($) {
    var Page = {};
    CKEDITOR.isLoaded=false;
    editor=CKEDITOR.replace('templatecontent',{
        width:'100%',
        height:350,
        startupMode:'source'
    });
    CKEDITOR.on('instanceReady', function() {
        CKEDITOR.isLoaded = true;
    } );
    Page.Event = {
        init : function() {
            this.initColum();
            this.addEvent();
        },
        initColum : function(){
            if(!getRequestUrl().tempId)return false
            $('#title').val(decodeURI(getRequestUrl().templateName)).attr('disabled',true)
            var listArr=[];
            if(getRequestUrl().index){
                if($('.active-iframe',self.document).length){
                    listArr=$('.active-iframe',self.document)[0].contentWindow.listArr;
                }else{
                    listArr=top.listArr;
                }
            }
            if(listArr.length && listArr[getRequestUrl().index].ext2){
                editor.setData(listArr[getRequestUrl().index].ext2)
                return false
            }
            var _args={
                templateId:getRequestUrl().tempId
            };
            $.ajax({
                url : '/template/cdStructuredTemplate/getList',
                data : _args,
                contentType : 'application/json;charset=utf-8',
                type: 'GET',
                sync:false,
                success : function(res) {
                    if(res.state===200){
                        var _data = res.results.resultList;
                        if(_data.length){
                            editor.setData(_data[0].ext2 ? _data[0].ext2 : _data[0].templateContent);
                        }
                    }
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    console.log(XMLHttpRequest.status);
                    console.log(textStatus);
                }
            });
        },
        addEvent : function () {

        }
    };
    Page.Event.init();
})(jQuery);